return g_string_free (path, FALSE);
}
-static char *
-get_delta_path (const char *from,
- const char *to,
- const char *target)
+char *
+_ostree_get_relative_static_delta_path (const char *from,
+ const char *to,
+ const char *target)
{
- char prefix[3];
guint8 csum_to[32];
char to_b64[44];
guint8 csum_to_copy[32];
+ GString *ret = g_string_new ("deltas/");
ostree_checksum_inplace_to_bytes (to, csum_to);
ostree_checksum_b64_inplace_from_bytes (csum_to, to_b64);
g_assert (memcmp (csum_to, csum_to_copy, 32) == 0);
- if (from == NULL)
- {
- prefix[0] = to_b64[0];
- prefix[1] = to_b64[1];
- prefix[2] = '\0';
- return g_strconcat ("deltas/", prefix, "/", ((char*)to_b64)+2, "/", target, NULL);
- }
- else
+ if (from != NULL)
{
guint8 csum_from[32];
char from_b64[44];
ostree_checksum_inplace_to_bytes (from, csum_from);
ostree_checksum_b64_inplace_from_bytes (csum_from, from_b64);
- prefix[0] = from_b64[0];
- prefix[1] = from_b64[1];
- prefix[2] = '\0';
- return g_strconcat ("deltas/", prefix, "/", ((char*)from_b64)+2, "-", to_b64, "/", target, NULL);
+ g_string_append_c (ret, from_b64[0]);
+ g_string_append_c (ret, from_b64[1]);
+ g_string_append_c (ret, '/');
+ g_string_append (ret, from_b64 + 2);
+ g_string_append_c (ret, '-');
}
+
+ g_string_append_c (ret, to_b64[0]);
+ g_string_append_c (ret, to_b64[1]);
+ if (from == NULL)
+ g_string_append_c (ret, '/');
+ g_string_append (ret, to_b64 + 2);
+
+ if (target != NULL)
+ {
+ g_string_append_c (ret, '/');
+ g_string_append (ret, target);
+ }
+
+ return g_string_free (ret, FALSE);
}
char *
-_ostree_get_relative_static_delta_path (const char *from,
- const char *to)
+_ostree_get_relative_static_delta_superblock_path (const char *from,
+ const char *to)
{
- return get_delta_path (from, to, "superblock");
+ return _ostree_get_relative_static_delta_path (from, to, "superblock");
}
char *
_ostree_get_relative_static_delta_detachedmeta_path (const char *from,
const char *to)
{
- return get_delta_path (from, to, "meta");
+ return _ostree_get_relative_static_delta_path (from, to, "meta");
}
char *
guint i)
{
gs_free char *partstr = g_strdup_printf ("%u", i);
- return get_delta_path (from, to, partstr);
+ return _ostree_get_relative_static_delta_path (from, to, partstr);
}
/*
#include "config.h"
+#include "ostree-core-private.h"
#include "ostree-repo-private.h"
#include "otutil.h"
cancellable, error))
goto out;
}
+
+ { gs_unref_ptrarray GPtrArray *deltas = NULL;
+ guint i;
+
+ if (!ostree_repo_list_static_delta_names (self, &deltas,
+ cancellable, error))
+ goto out;
+
+ for (i = 0; i < deltas->len; i++)
+ {
+ const char *deltaname = deltas->pdata[i];
+ const char *dash = strchr (deltaname, '-');
+ const char *to = NULL;
+ gboolean have_commit;
+ gs_free char *from = NULL;
+ gs_free char *deltadir = NULL;
+
+ if (!dash)
+ {
+ to = deltaname;
+ }
+ else
+ {
+ from = g_strndup (deltaname, dash - deltaname);
+ to = dash + 1;
+ }
+
+ if (!ostree_repo_has_object (self, OSTREE_OBJECT_TYPE_COMMIT,
+ to, &have_commit,
+ cancellable, error))
+ goto out;
+
+ if (have_commit)
+ continue;
+
+ deltadir = _ostree_get_relative_static_delta_path (from, to, NULL);
+
+ if (!gs_shutil_rm_rf_at (self->repo_dir_fd, deltadir,
+ cancellable, error))
+ goto out;
+ }
+ }
+
ret = TRUE;
*out_objects_total = (data.n_reachable_meta + data.n_unreachable_meta +
data.n_reachable_content + data.n_unreachable_content);